﻿using System;
using System.Globalization;

namespace JTLeigh.Tools.Development.CopySourceAsHtml
{

    /// <summary>
    /// Provides methods for ensuring code is safe and fails fast.
    /// </summary>
    public static class Safety
    {
        #region Static Methods

        /// <summary>
        /// Asserts that the supplied argument value is not <see langword="null"/>.
        /// </summary>
        /// <param name="argumentName">The argument name.</param>
        /// <param name="argumentValue">The argument value.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="argumentName"/> or
        /// <paramref name="argumentValue"/> is <see langword="null"/>.</exception>
        public static void AssertArgumentNotNull(string argumentName, object argumentValue)
        {
            if (argumentName == null)
            {
                throw new ArgumentNullException("argumentName", "Argument 'argumentName' must not be null.");
            }
            if (argumentValue == null)
            {
                throw new ArgumentNullException(argumentName, String.Format(CultureInfo.InvariantCulture, "Argument '{0}' must not be null.", argumentName));
            }
        }

        /// <summary>
        /// Asserts that the supplied value is <see langword="true"/>.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="message">The message to throw if the supplied value is <see langword="false"/>.</param>
        /// <exception cref="InvalidOperationException">Thrown if <paramref name="value"/> is
        /// <see langword="false"/>.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="message"/> is 
        /// <see langword="null"/>.</exception>
        public static void AssertIsTrue(bool value, string message)
        {
            Safety.AssertArgumentNotNull("message", message);

            if (!value)
            {
                throw new InvalidOperationException(message);
            }
        }

        #endregion // Static Methods
    }
}
